<!--
This creates the LWUIT release in Series-40-binaries folder
folder structure:
    bin 
    doc
    examples
    resourceEditor

bin:
    contains binaries for different sdks, these binaries are 
    created by S40 project. It also contains IO folder with IO binaries.
doc:
    contains javadocs and lwuit developer's guide pdf
    these are copied from the docs folder
examples:
    contains lwuit examples from Apps folder
resourceEditor:
    contains the resourceEditor binary.
    This is copied from the tools/Lwuit-ResourceEditor folder

Note! the resourceeditor target will only call maven to build the
resourceeditor. If you get any compile errors check the build-instructions
from the tools/Lwuit-ResourceEditor folder. After you can build
the ResourceEditor without problems you can use this script.

-->
<project name="LWUIT-Release" default="dist" basedir=".">
    <property name="examples" location="Apps" />
    <property name="docs" location="docs" />
    <property name="javadocs" location="${docs}/javadocs" />
    <property name="devguide" location="${docs}/LWUIT_Developer_Guide.pdf" />
    <property name="releasepath" location="Series-40-binaries" />
    <property name="releasenotes" location="releasenotes" />
    <property name="s40port" location="Ports/Nokia/S40" />
    <property name="RE" location="tools/Lwuit-ResourceEditor" />
    <property name="IO" location="IO" />
    <property name="IO-MIDP" location="Ports/MIDP/IO_MIDP" />
    <property name="package-version" value="1.0" />

    <target name="init">
        <mkdir dir="${releasepath}" />
        <mkdir dir="${releasepath}/bin" />
        <mkdir dir="${releasepath}/doc" />
        <mkdir dir="${releasepath}/examples" />
        <mkdir dir="${releasepath}/resourceeditor" />
        <mkdir dir="${releasepath}/releasenotes" />
    </target>
    <!--build s40 port -->
    <target name="S40-build" depends="init">
        <ant antfile="${s40port}/antenna-build.xml" useNativeBasedir="true" target="release" />
    </target>
    <!-- build IO lib -->
    <target name="IO-build" depends="init">
        <ant antfile="${IO}/build.xml" useNativeBasedir="true" target="build" />
        <ant antfile="${IO-MIDP}/build.xml" useNativeBasedir="true" target="build" />
        <copy file="${IO}/dist/IO.jar" todir="${releasepath}/bin/IO" />
        <copy file="${IO-MIDP}/dist/IO.jar" tofile="${releasepath}/bin/IO/IO-MIDP.jar" />
    </target> 
    <!-- copy examples -->
    <target name="copy-examples" depends="init">
        <copy todir="${releasepath}/examples">
            <fileset dir="${examples}" >
                <exclude name="**/TimeZone/**" />
                <exclude name="**/LWUITDemo-original/**" />
                <exclude name="**/LWUITSpeed/**" />
                <exclude name="**/build/**" />
                <exclude name="**/dist/**" />
                <exclude name="**/bin/**" />
                <exclude name="**/.mtj.tmp/**" />
            </fileset>
        </copy>
    </target>
    <!-- copy docs -->
    <target name="copy-docs" depends="init">
        <copy todir="${releasepath}/doc/javadoc" >
            <fileset dir="${javadocs}" />
        </copy>
        <copy file="${devguide}" todir="${releasepath}/doc" />
    </target>
    <target name="copy-notes" depends="init">
        <copy todir="${releasepath}/releasenotes" >
            <fileset dir="${releasenotes}" />
        </copy>
    </target>
    <!-- build & copy ResourceEditor -->
    <target name="ResourceEditor" depends="init" >
        <ant antfile="${RE}/build.xml" useNativeBasedir="true" target="package" /> 
        <copy todir="${releasepath}/resourceeditor/lib">
            <fileset dir="${RE}/target/lib" />
        </copy>
        <copy file="${RE}/target/Lwuit-ResourceEditor-1.0-SNAPSHOT.jar" 
            tofile="${releasepath}/resourceeditor/Lwuit-ResourceEditor-1.0.jar" />
        <copy file="${RE}/ResourceEditor.bat" 
            todir="${releasepath}/resourceeditor" />
    </target>
    <target name="fix-paths" depends="S40-build, IO-build, copy-examples" >
        <!-- ContactBookDemo -->
        <replace file="${releasepath}/examples/ContactBookDemo/nbproject/project.properties"
            value="../../bin/sdk2.0/S40-with-themes.jar"
            token="../../Series-40-binaries/bin/sdk2.0/S40-with-themes.jar"
        />
        <replace file="${releasepath}/examples/ContactBookDemo/nbproject/project.properties"
            value="../../bin/IO/IO-MIDP.jar"
            token="../../Series-40-binaries/bin/IO/IO-MIDP.jar"
        />
        <!-- LWUITBrowser -->
        <replace file="${releasepath}/examples/LWUITBrowser/nbproject/project.properties"
            value="../../bin/sdk2.0/S40-with-themes.jar"
            token="../../Series-40-binaries/bin/sdk2.0/S40-with-themes.jar"
        />
        <!-- LWUITDemo -->
        <replace file="${releasepath}/examples/LWUITDemo/nbproject/project.properties"
            value="../../bin/sdk2.0/S40-with-themes.jar"
            token="../../Series-40-binaries/bin/sdk2.0/S40-with-themes.jar"
        /> 
        <!-- Makeover -->
        <replace file="${releasepath}/examples/Makeover/nbproject/project.properties"
            value="../../bin/sdk2.0/S40-with-themes.jar"
            token="../../Series-40-binaries/bin/sdk2.0/S40-with-themes.jar"
        />
        <replace file="${releasepath}/examples/Makeover/nbproject/project.properties"
            value="../../bin/IO/IO-MIDP.jar"
            token="../../Series-40-binaries/bin/IO/IO-MIDP.jar"
        />
        <!-- Tipster -->
        <replace file="${releasepath}/examples/Tipster/nbproject/project.properties"
            value="../../bin/sdk2.0/S40-with-themes.jar"
            token="../../Series-40-binaries/bin/sdk2.0/S40-with-themes.jar"
        />
        <replace file="${releasepath}/examples/Tipster/nbproject/project.properties"
            value="../../bin/IO/IO-MIDP.jar"
            token="../../Series-40-binaries/bin/IO/IO-MIDP.jar"
        />
        <!-- birthdays -->
        <antcall target="fix-properties">
            <param name="app-path" value="${releasepath}/examples/LWUIT_Birthdays" />
        </antcall>
        <!-- categorybardemo -->
        <antcall target="fix-properties">
            <param name="app-path" value="${releasepath}/examples/LWUIT_CategoryBarDemo" />
        </antcall>
        <!-- gesturesDemo -->
        <antcall target="fix-properties">
            <param name="app-path" value="${releasepath}/examples/LWUIT_GesturesDemo" />
        </antcall>
        <!-- listdemo -->
        <antcall target="fix-properties">
            <param name="app-path" value="${releasepath}/examples/LWUIT_ListDemo" />
        </antcall>
        <!-- puzzle -->
        <antcall target="fix-properties">
            <param name="app-path" value="${releasepath}/examples/LWUIT_Puzzle" />
        </antcall>
        <!-- Tourist -->
        <antcall target="fix-properties">
            <param name="app-path" value="${releasepath}/examples/LWUIT_TouristAttractions" />
        </antcall>
        <!-- Rlinks, has special replace since not the default jar -->
        <replace file="${releasepath}/examples/RLinks/nbproject/project.properties"
            value="../../bin/sdk2.0/S40-no-themes.jar"
            token="../../Series-40-binaries/bin/sdk2.0/S40-no-themes.jar"
        /> 
        <!-- Lwuitspeed -->
        <!--<replace file="${releasepath}/examples/LWUITSpeed/nbproject/project.properties"
            value="../../bin/sdk2.0/S40-no-themes.jar"
            token="../../Series-40-binaries/bin/sdk2.0/S40-no-themes.jar"
        />-->
    </target>

    <target name="fix-properties">
        <replace file="${app-path}/nbproject/project.properties"
            value="../../bin/sdk2.0/S40-with-themes.jar"
            token="../../Series-40-binaries/bin/sdk2.0/S40-with-themes.jar"
        />
    </target>
    <target name="dist" depends="S40-build, IO-build, copy-examples, copy-docs, ResourceEditor, fix-paths, copy-notes" />

    <!-- create a single zip package from Series-40-binaries folder -->
    <target name="package" depends="dist">
        <zip destfile="LWUIT-for-Series-40-binaries-${package-version}.zip">
            <zipfileset dir="Series-40-binaries" prefix="LWUIT-for-Series-40-${package-version}" />
        </zip>
    </target>
    <target name="clean">
        <delete dir="${releasepath}" />
    </target>

</project>
